package common.message
{
	
	import com.greensock.TweenMax;
	
	import common.GlobalSet;
	import common.text.DefaultHtmlLinkStyleSheet;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.utils.setTimeout;
	
	import kernel.application.ApplicationDisplay;

	public class PublicOneNotice extends Sprite
	{
		/**
		 * 行为公告显示的时间：毫秒
		 */
		public static var showTime:uint = 5000;
		
		private var _txt:TextField;
		private var _tf:TextFormat;
		private var _hideCall:Function;
		
		public function PublicOneNotice(message:Array,hideCall:Function,viewWidth:Number)
		{
			this.mouseEnabled = false;
			_hideCall = hideCall;
			_txt = new TextField();
			_txt.width = viewWidth;
			_tf = new TextFormat();
			_tf.size = 16;
			_tf.color = message[1];
			_tf.bold = false;
			_tf.align = TextFormatAlign.CENTER;
			_txt.multiline = true;
			_txt.wordWrap = true;
			_txt.width = ApplicationDisplay.stage.stageWidth-200;
			_txt.height = 19;
			_txt.defaultTextFormat = _tf;
			_txt.styleSheet = DefaultHtmlLinkStyleSheet.getShareInstance();
			_txt.htmlText = message[0];
			_txt.width = _txt.textWidth +10;
			_txt.height = _txt.textHeight +8;
			_txt.selectable = false;
			_txt.width = _txt.textWidth+10;
			_txt.x = -int(_txt.width/2);
			_txt.filters = GlobalSet.defaultTextFilter;
			this.addChild(_txt);
			this.alpha = 0;
			TweenMax.to(this,0.5,{alpha:1});
			setTimeout(hideMe,showTime);
		}
		
		public function hideMe():void
		{
			TweenMax.to(this,0.4,{alpha:0,onComplete:removeMe});
		}
		public function removeMe():void
		{
			this.parent.removeChild(this);
			_hideCall();
		}
	}
}